package com.wanglianyun.service;

import com.wanglianyun.event.RegisterSuccessEvent;
import com.wanglianyun.request.RegisterRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

/**
 * Description:
 * Copyright: Copyright (c) 2024
 * Create Time: 2024-09-26 21:07
 *
 * @author wanglianyun
 */
@Service
public class RegisterService {

    @Autowired
    private ApplicationContext applicationContext;

    public void register(RegisterRequest registerRequest) {
        // 执行自己的业务逻辑，执行完之后发布一个自己定义的RegisterSuccessEvent事件，监听整个事件的监听器监听到该事件之后开始执行自己的逻辑
        System.out.println("开发触发事件");
        applicationContext.publishEvent(new RegisterSuccessEvent(registerRequest));
        System.out.println("触发事件结束");
    }
}
